package edu.chinasoft.service;

import edu.chinasoft.domain.PageUnitForUser;
import edu.chinasoft.domain.User;
import edu.chinasoft.mapper.UserMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service("userService")
public class UserServiceImp implements UserService {
    @Autowired
    @Qualifier(value = "userMapper")
    private UserMapper userMapper;
    private Logger logger = LoggerFactory.getLogger(UserServiceImp.class);
    @Transactional(readOnly = false,propagation = Propagation.REQUIRED)
    @Override
    public Boolean insertUser(User user){
        logger.info("UserServiceImp>>>insertUser start ……");
        boolean result_user = userMapper.insertUser(user);
        logger.info("UserServiceImp>>>insertUser end ……");
        return result_user;
    }
    @Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
    @Override
    public List<User> selectUserByUserName(User user){
        List<User> userList = userMapper.selectUserByUserName(user);
        return userList;
    }
    @Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
    @Override
    public User selectUserByNameAndPassword(User user){
        User result = userMapper.selectUserByNameAndPassword(user);
        return result;
    }
    @Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
    @Override
    public PageUnitForUser getRecordNum(){
        logger.info("UserServiceImp>>>getRecordNum start ……");
        PageUnitForUser recordNum = userMapper.getRecordNum();
        logger.info("UserServiceImp>>>getRecordNum end ……");
        return recordNum;
    }
    @Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
    @Override
    public List<User> selectUnitUser(Map<String,Object> map){
        logger.info("UserServiceImp>>>selectUnitUser start ……");
        List<User> userList = userMapper.selectUnitUser(map);
        logger.info("UserServiceImp>>>selectUnitUser end ……");
        return userList;
    }
    @Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
    @Override
    public boolean deleteUserById(User user){
        logger.info("UserServiceImp>>>selectUnitUser start ……");
        boolean result = userMapper.deleteUserById(user);
        logger.info("UserServiceImp>>>selectUnitUser end ……");
        return result;
    }
    @Transactional(readOnly = false,propagation = Propagation.REQUIRED)
    @Override
    public boolean updateUserByUserId(User user){
        logger.info("UserServiceImp>>>updateUserByUserId start ……");
        
        boolean result_user = userMapper.updateUserByUserId(user);
        logger.info("UserServiceImp>>>updateUserByUserId end ……");
        return result_user;
    }
    @Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
    @Override
    public User selectUserById(User user){
        logger.info("UserServiceImp>>>selectUserById start ……");
        User result = userMapper.selectUserById(user);
        logger.info("UserServiceImp>>>selectUserById end ……");
        return result;
    }
    @Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
    @Override
    public boolean updateUserStatusById(User user){
        logger.info("UserServiceImp>>>selectUserById start ……");
        boolean result = userMapper.updateUserStatusById(user);
        logger.info("UserServiceImp>>>selectUserById end ……");
        return result;
    }

}
